import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { environment } from '@env/environment';
import { SimpleGuard } from '@delon/auth';
// layout
import { MSLayoutComponent } from '@brand';
// single pages
import { CallbackComponent } from './callback/callback.component';
import { AuthGuardService } from './services/auth-guard.service';

const routes: Routes = [
  // Full pages
  {
    path: '',
    component: MSLayoutComponent,
    canActivate: [SimpleGuard],
    children: [
      { path: '', redirectTo: 'home', pathMatch: 'full' },
      { path: 'home', loadChildren: './home/home.module#HomeModule' },
      { path: 'user', loadChildren: './user/user.module#UserModule' },
      { path: 'admin', canActivateChild: [AuthGuardService], loadChildren: './admin/admin.module#AdminModule' },
      { path: 'msg', canActivateChild: [AuthGuardService], loadChildren: './msg/msg.module#WebMsgModule' },
      { path: 'notification', loadChildren: './notific/notific.module#NotificModule' },
      { path: 'system', canActivateChild: [AuthGuardService], loadChildren: './system/system.module#SystemModule' },
      { path: 'prod', canActivateChild: [AuthGuardService], loadChildren: './product/product.module#ProductModule' },
      // Exception
      {
        path: 'exception',
        loadChildren: './exception/exception.module#ExceptionModule',
      },
    ],
  },
  // Single pages (Not sidebar)
  {
    path: '',
    component: MSLayoutComponent,
    canActivate: [SimpleGuard],
    data: { hasAllNav: true, hasSidebar: false },
    children: [],
  },
  {
    path: 'account',
    loadChildren: './account/account.module#AccountModule',
  },
  { path: 'callback/:type', component: CallbackComponent },
  { path: '**', redirectTo: 'exception/404' },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      useHash: environment.useHash,
      scrollPositionRestoration: 'top',
    }),
  ],
  exports: [RouterModule],
})
export class RouteRoutingModule {}
